package com.isunland.managesystem.ui;

import android.os.Bundle;
import com.google.gson.Gson;
import com.isunland.managesystem.base.BaseNetworkDialogFragment;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.entity.CustomerDialog;
import com.isunland.managesystem.entity.CustomerNeed;
import com.isunland.managesystem.entity.CustomerNeedOriginal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class CustomerNeedDialogFragment extends BaseNetworkDialogFragment {
  private String nameId;

  @Override public void onCreate(Bundle savedInstanceState) {
    //客户id
    nameId = getArguments().getString(CustomerVisitFragment.EXTRA_CODE);
    super.onCreate(savedInstanceState);
  }

  @Override public ArrayList<CustomerDialog> resolveResponse(String arg0) {
    ArrayList<CustomerDialog> list = new ArrayList<CustomerDialog>();

    CustomerNeedOriginal contractContentOriginal =
        new Gson().fromJson(arg0, CustomerNeedOriginal.class);

    List<CustomerNeed> dataList = contractContentOriginal.getRows();

    if (dataList == null || dataList.size() == 0) {

      return null;
    }
    for (int i = 0; i < dataList.size(); i++) {
      list.add(new CustomerDialog(dataList.get(i).getNeedProductDesc(), dataList.get(i).getId()));
    }
    return list;
  }

  @Override public String getUrl() {
    return ApiConst.URL_CUSTOMER_NEED_LIST;
  }

  @Override public HashMap<String, String> getparameters() {

    HashMap<String, String> params = new HashMap<String, String>();
    params.put("customerId", nameId);

    return params;
  }
}

